<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家资料控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajucompanyinfoController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete',
			'foreverdelete_deep',
			'input_change_ajax',
			'input_change_unique',
			'forbid',
			'closeitem',
			'openitem',
			'resume',
			'clear_recycle',
			'save_sort',
			'insert',
			'add',
			'edit',
			'update'
		);
		
		parent::init__();
	}
	
	public function index($sName=null,$bDisplay=true){
		$this->company_();
		$this->display();
	}
	
	public function info(){
		$nType=intval(Q::G('type'));
		if(!in_array($nType,array(1,2))){
			$nType=1;
		}

		$this->company_();

		if($nType==1){
			// 服务区域和类型
			$oJiajucompanyclass=Q::instance('JiajucompanyclassModel');
			$this->assign('arrScale',$oJiajucompanyclass->getClass(1));
			$this->assign('arrOutput',$oJiajucompanyclass->getClass(4));
			$this->assign('arrHomeclass',$oJiajucompanyclass->getClass(2));
			$this->assign('arrBusinessclass',$oJiajucompanyclass->getClass(3));
			$this->assign('arrStyleclass',$oJiajucompanyclass->getClass(52));

			$oJiajucompany=Q::instance('JiajucompanyModel');
			$this->assign('arrBusinessclass_',$oJiajucompany->getClass($GLOBALS['_company_']['jiajucompany_id'],'jiajucompanybusinessclass'));
			$this->assign('arrDistrict_',$oJiajucompany->getClass($GLOBALS['_company_']['jiajucompany_id'],'jiajucompanydistrict'));
			$this->assign('arrHomeclass_',$oJiajucompany->getClass($GLOBALS['_company_']['jiajucompany_id'],'jiajucompanyhomeclass'));
			$this->assign('arrStyleclass_',$oJiajucompany->getClass($GLOBALS['_company_']['jiajucompany_id'],'jiajucompanystyleclass'));
		}

		// 更新
		if($this->isPost()){
			$oJiajucompany=JiajucompanyModel::F('jiajucompany_id=?',$GLOBALS['_company_']['jiajucompany_id'])->getOne();
			
			if($nType==2){
				$oJiajucompany->save('update');
				if($oJiajucompany->isError()){
					$this->E($oJiajucompany->getErrorMessage());
				}else{
					$this->S('商家扩展介绍保存成功');
				}
			}else{
				$oJiajucompany->updateData();
				if($oJiajucompany->isError()){
					$this->E($oJiajucompany->getErrorMessage());
				}

				$this->S('商家基本资料保存成功');
			}
		}

		$this->assign('nType',$nType);
		$this->display('jiajucompanyinfo+info'.$nType);
	}

	public function master(){
		// 更新绑定帐号信息
		if($this->isPost()){
			$oJiajucompanymaster=JiajucompanymasterModel::F('jiajucompany_id=?',$GLOBALS['_company_']['jiajucompany_id'])->getOne();
			$oJiajucompanymaster->save('update');
			if($oJiajucompanymaster->isError()){
				$this->E($oJiajucompanymaster->getErrorMessage());
			}else{
				$this->S('商家帐号绑定信息保存成功');
			}
		}
		
		$this->display();
	}

	public function baidumap(){
		$this->display();
	}

	protected function company_(){
		$arrCompany=Model::F_('jiajucompany','@A')
			->setColumns('A.jiajucompany_id')
			->where(array('jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))
			->join(Q::C('DB_PREFIX').'site AS C','C.site_name','A.site_id=C.site_id')
			->joinLeft(Q::C('DB_PREFIX').'district AS D','D.district_name AS province_name','A.province_id=D.district_id')
			->joinLeft(Q::C('DB_PREFIX').'district AS E','E.district_name AS city_name','A.city_id=E.district_id')
			->joinLeft(Q::C('DB_PREFIX').'district AS F','F.district_name AS district_name','A.district_id=F.district_id')
			->joinLeft(Q::C('DB_PREFIX').'district AS G','G.district_name AS community_name','A.community_id=G.district_id')
			->joinLeft(Q::C('DB_PREFIX').'jiajucompanyclass AS H','H.jiajucompanyclass_name AS scale_name','A.jiajucompany_scaleid=H.jiajucompanyclass_id')
			->joinLeft(Q::C('DB_PREFIX').'jiajucompanyclass AS I','I.jiajucompanyclass_name AS output_name','A.jiajucompany_outputid=I.jiajucompanyclass_id')
			->getOne();

		// 读取服务区域
		$arrDistricts=Model::F_('jiajucompanydistrict','@A')->setColumns('A.*')
			->where(array('A.jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))
			->join(Q::C('DB_PREFIX').'district AS B','B.district_name','A.district_id=B.district_id')
			->getAll();

		// 读取家庭装修和商业装修等
		$arrHomeclasss=Model::F_('jiajucompanyhomeclass','@A')->setColumns('A.*')
			->where(array('A.jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))
			->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
			->getAll();
		
		$arrBusinessclasss=Model::F_('jiajucompanybusinessclass','@A')->setColumns('A.*')
			->where(array('A.jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))
			->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
			->getAll();
		
		$arrStyleclasss=Model::F_('jiajucompanystyleclass','@A')->setColumns('A.*')
			->where(array('A.jiajucompany_id'=>$GLOBALS['_company_']['jiajucompany_id']))
			->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
			->getAll();

		$this->assign('arrCompany',$arrCompany);
		$this->assign('arrDistricts',$arrDistricts);
		$this->assign('arrHomeclasss',$arrHomeclasss);
		$this->assign('arrStyleclasss',$arrStyleclasss);
		$this->assign('arrBusinessclasss',$arrBusinessclasss);
	}

}
